#include "MainScene.h"
#include "GameScene.h"

#define MENU_TAG_PLAY 1
#define MENU_TAG_SETTING 2

bool MainScene::init()
{
    bool ret = false;
    do 
    {
        CC_BREAK_IF(!CCScene::init());

        m_bgLayer = CCLayer::create();
        m_menuLayer = CCLayer::create();
        m_spriteLayer = CCLayer::create();

        this->addChild(m_bgLayer);
        this->addChild(m_menuLayer);
        this->addChild(m_spriteLayer);

        CCSize winSize = CCDirector::sharedDirector()->getWinSize();

        CCSprite * bg = CCSprite::create("background-parallax.png");
        this->m_bgLayer->addChild(bg);
        bg->setPosition(ccp(winSize.width /2 ,winSize.height /2));



        CCMenuItemFont::setFontSize(28);
        CCMenuItemFont *menuPlay = CCMenuItemFont::create("Play",this,menu_selector(MainScene::menuCallback));
        menuPlay->setTag(MENU_TAG_PLAY);
        CCMenuItemFont *menuSetting = CCMenuItemFont::create("Setting",this,menu_selector(MainScene::menuCallback));
        menuSetting->setTag(MENU_TAG_SETTING);
        CCMenu *menu = CCMenu::create(menuPlay,menuSetting,NULL);
        menu->alignItemsVertically();
        this->m_menuLayer->addChild(menu);

        ret = true;
    } while (false);
    return ret;
}

void MainScene::menuCallback( CCMenuItem * pSender )
{
    int tag = pSender->getTag();
    if(tag == MENU_TAG_PLAY)
    {
        CCDirector::sharedDirector()->replaceScene(GameScene::create());
    }
    if(tag == MENU_TAG_SETTING)
    {


    }
}
